<style>
td {
	border: solid #68BADA;
	border-width: 0px 1px 1px 0px;
	padding: 5px;
	text-align: center
}
table {
	border: solid #68BADA;
	border-width: 1px 0px 0px 1px;
}
.odd {
	background: none repeat scroll 0 0 #EEEEEE;
}
.even {
	background: none repeat scroll 0 0 #FFFFFF;
}
.three {
	background: none repeat scroll 0 0 #E5F1F4;
}
.jg {
	background: none repeat scroll 0 0 #ADD9ED;
}
.head {
	background: none repeat scroll 0 0 #90D8F0;
}
input, img {
	vertical-align: middle;
}
</style>
<script>
function process(oid,msg){
	if(!confirm('確認要'+msg+':'+oid)){
		return false;
	}
	$.post('<?php echo CHtml::normalizeUrl(array('/order/process'));?>',{'oid':oid}, function (data) {
        var ret = $.parseJSON(data);
        if (ret != null && ret.success != null && ret.success) {
			alert(ret.msg);
			location.reload(true);
        }
	});	
}
function cancel(oid){
	if(!confirm('確認要取消:'+oid)){
		return false;
	}
	$.post('<?php echo CHtml::normalizeUrl(array('/order/cancel'));?>',{'oid':oid}, function (data) {
        var ret = $.parseJSON(data);
        if (ret != null && ret.success != null && ret.success) {
			alert(ret.msg);
			location.reload(true);
        }
	});	
}
</script>
<?php
$this->breadcrumbs=array(
	'訂單管理'=>array('admin'),
	'訂單列表',
);
?>
<div style="width:100%; float:left; margin-bottom:10px; text-align:right;">
	<form action="<?=Yii::app()->createUrl('order/index')?>" name="jobForm" id="jobForm" method="get">		
		<?php echo CHtml::dropDownList('paytype',$search['paytype'], Yii::app()->params['paytype']);?>
		<?php echo CHtml::dropDownList('status',$search['status'], Yii::app()->params['orderstatus']);?>
		創建時間: <input type="text" name="s" id="s" value="<?= $search['s'] ?>" readonly="readonly" style="width:88px;" />
		<img onclick="displayCalendar(document.jobForm.s,'yyyy-mm-dd',this)" style="cursor:pointer;" src="images/calendar.png" /> - 
		<input type="text" name="e" id="e" value="<?= $search['e'] ?>" readonly="readonly" style="width:88px;" />
		<img onclick="displayCalendar(document.jobForm.e,'yyyy-mm-dd',this)" style="cursor:pointer;" src="images/calendar.png" />
		用戶： <input type="text" name="username" value="<?php if(isset($search['username']))echo $search['username'];?>" id="username" size="12" />
		訂單編號： <input type="text" name="oid" value="<?php if(isset($search['oid']))echo $search['oid'];?>" id="oid" size="10" />
		<input type="image" src="images/go.png" name="jobSub" id="jobSub" value="Go" />
		<input type="hidden" name="r" value="order/index" />
	</form>
</div>
<table cellspacing="0" cellpadding="0" width="100%" class="tbl">
	<tr class="head">
		<td width="2%">ID</td>
		<td width="10%">訂單編號</td>
		<td width="15%">用戶</td>
		<td width="8%">訂單金額</td>
		<td width="15%">付款方式</td>
		<td width="10%">狀態</td>
		<td width="12%">創建時間</td>
		<td width="12%">更新時間</td>
		<td width="5%">操作</td>
		<td width="5%">詳情</td>
		<td>取消</td>
	</tr>
	<?php
    $i = 0;
    $cssArr = array(0 => 'even', 1 => 'odd', 2 => 'three');
    foreach ($rowTable as $item) {
        $trClass = $cssArr[$i % 3];
        $i++;
		switch($item->status){
			case 1:
				$msg = '付款';
				$cancel = '取消';
				break;
			case 2:
				$msg = '出貨';
				$cancel = '取消';
				break;
			case 3:
				$msg = '完成';
				$cancel = '取消';
				break;
			default:
				$msg = '';
				$cancel = '';
		}
        ?>
	<tr class="<?= $trClass ?>">
		<td>
			<?=$i?>
		</td>
		<td>
			<?=$item->oid?>
		</td>
		<td>
			<?=$item->user->username?>
		</td>
		<td>
			<?=$item->total_final?>
		</td>
		<td>
			<?=Yii::app()->params['paytype'][$item->pay_type]?>
		</td>
		<td>
			<?=Yii::app()->params['orderstatus'][$item->status]?>
		</td>
		<td>
			<?=date('Y-m-d',strtotime($item['dateline']))?>
		</td>
		<td>
			<?=date('Y-m-d',strtotime($item['updated']))?>
		</td>
		<td><a onclick="process('<?=$item->oid?>','<?=$msg?>')" href="###"><?=$msg?></a></td>
		<td><a href="<?=Yii::app()->createUrl('order/view',array('id'=>$item->oid))?>">詳情</a></td>
		<td><a onclick="cancel('<?=$item->oid?>')" href="###"><?=$cancel?></a></td>
	</tr>
	<?php
    }
    ?>
</table>
<div id="pager" align="center">
	<?php  
	$this->widget('CLinkPager',array(  
		'header'=>'',  
		'firstPageLabel' => '<<',
		'lastPageLabel' => '>>',
		'prevPageLabel' => '<',
		'nextPageLabel' => '>',
		'pages' => $pages,  
		'maxButtonCount'=>13  
		));  
?>
</div>
